<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>
<%
	request.setAttribute("title", "提现");
%>
<%@ include file="/WEB-INF/views/shared/master/weContentHeader.jsp"%>

<style>
/* ---------------遮罩层 ------------------*/
#cover{
position:fixed;
z-index:1000;
top:0px;
left:0px;
display:none;
width:100%;
height:100%;
opacity:0.5;
background:#000;
}
 /* --------------6位支付密码样式------------------- */
 .paycontainer{
        margin-left:30px;
        height:50px;
        position: relative;
    }
    .paypasswordcontainer{
        width: 300px;
        height: 46px;
        font-size: 12px;
        position: absolute;
        color: #ffffff;
        z-index:9;
        opacity:0.2;
        -webkit-user-select: initial; /*取消禁用选择页面元素*/
        background-color: #ffffff;
        outline:none;
    }
    .sixpassword{
        width: 300px;
        height: 22px;
        position: absolute;
        top:1px;
        left:1px;
        padding:13px 0;
        cursor: text;
        background: #fff;
        border-radius: 5px;
    }
    .sixpassword i{
        display: inline-block;
        width: 49px;
        height: 22px;
        border-left: 1px solid #cccccc;
        float: left;
    }
    .sixpassword i:first-child{
        border-left:0;
    }
    .sixpassword i.active{
        background: url("https://t.alipayobjects.com/images/rmsweb/T1nYJhXalXXXXXXXXX.gif") no-repeat 60% center;
    }
    .sixpassword b{
        width: 7px;
        height: 7px;
        background-color: #000;
        display: block;
        margin: 7px auto;
        display: none;
        border-radius: 50%;
    }
    .guangbiao{
        width: 48px;
        height: 46px;
        display: block;
        position: absolute;
        display: block;
        left: 0px;
        top: 0px;
        border: 1px solid #00ffff;
        border-radius: 5px;
        box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6) ;
    }

/* ----------------------------------- */
body{
	background-color: #f5f5f5;
}
.weui-cells {
	margin-top: 0px;
}

.withdrawmoney>p {
	padding: 15px 10px;
	color: black;
	font-size: 16px;
}

.money {
	margin: 0px 10px;
	color: red;
}

#exchangeMoney{
	color: red;
}

.color-blue {
	color: #2196F3;
}

.bottom-btn {
	margin: 15px;
	padding: 2px;
	background-color: #2196F3;
}

.weui-btn_primary:not (.weui-btn_disabled ):active {
	background-color: #2196F3;
}

.weui-btn_disabled {
	background-color: #79c0f9 !important;
	color:
}

.share {
	border-bottom: 0px;
}

.service-award {
	border-top: 2px solid #eee;
}

#shareLevel {
	display: none;
}

.share-award {
	border-bottom: 0px;
}

.weui-cell_define {
	-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
	color: inherit
}

.weui-cell {
	background-color: white;
}
.weui-cell:before{
	border-top:0px solid #e5e5e5;
}
.weui-cell_define .weui-cell__ft {
	padding-right: 13px;
	position: relative
}

.weui-cell_define .weui-cell__ft:after {
	content: " ";
	display: inline-block;
	height: 6px;
	width: 6px;
	border-width: 0 2px 2px 0;
	border-color: #c8c8cd;
	border-style: solid;
	-webkit-transform: matrix(.71, .71, -.71, .71, 0, 0);
	transform: matrix(.71, .71, -.71, .71, 0, 0);
	position: relative;
	top: -2px;
	position: absolute;
	top: 50%;
	margin-top: -4px;
	right: 2px
}
</style>

<%@ include file="/WEB-INF/views/shared/master/weTitle.jsp"%>


<div class="goback" data-back-href="<c:url value='/wechat/acc/myWealth/myWealth'/>"></div>

<input type="hidden" class="minMoney" value="${minMoney.param}"/>
<input type="hidden" class="allMoney" value="${accountInfo.balance}"/>


<div class="weui-cell" style="margin-top: 2rem">
	<div class="weui-cell__bd">
		<p>提现</p>
	</div>
	<div class="weui-cell__ft">
		单笔最高￥${perLimit.param}
	</div>
</div>
<div class="weui-cell"  style="border-bottom: 1px solid #dbdbdb;border-bottom-left-radius: 0.2rem;border-bottom-right-radius: 0.2rem ">
	<div class="weui-cell__hd">
		<span style="font-size: 25px; color: black; font-weight: 500; padding-right: 10px">￥</span>
	</div>
	<div class="weui-cell__bd">
		<input class="weui-input selected-color" id="money" type="number" placeholder="请输入提现金额" style="font-size: 18px;" onkeyup="btnColor(),checkMoney()"/>
	</div>
</div>
<span class="info" style="color: #ea693f;margin-left: 20px" hidden></span>
<div class="weui-cell" style="padding-top: 1rem;padding-bottom: 1rem">
	<div class="weui-cell__bd">
		<p>余额：￥<fmt:formatNumber type="number" value="${accountInfo.balance}" minFractionDigits="0"/></p>
	</div>
	<div class="weui-cell__ft">
		<a href="javascript:withdrawals();" class="weui-cell__ft" style="color: #1fa0db">全部提现</a>
	</div>
</div>

<div style="z-index: 500;margin-top: 1.5rem">
	<a href="javascript:withdraw();"data-href="<c:url value='/wechat/acc/myWealth/myWealth'/>"
		class="weui-btn weui-btn_primary bottom-btn withdraw weui-btn_disabled" id="btn">提&nbsp;&nbsp;&nbsp;&nbsp;现
	</a>
</div>

<div class="weui-cell" style="background-color: #f5f5f5;color: #333333">
	<div class="weui-cell__bd">
		<p style="font-size: 20px">提现须知</p>
	</div>
</div>
<div class="weui-cell" style="background-color: #f5f5f5;padding: 2px 15px;color: #666666">
	<div class="weui-cell__bd">
		<p>${minLimit.name}：${minLimit.param}&nbsp;&nbsp;${minLimit.unit}</p>
	</div>
	<div class="weui-cell__ft"></div>
</div>
<div class="weui-cell" style="background-color: #f5f5f5;padding: 2px 15px;color: #666666">
	<div class="weui-cell__bd">
		<p>${withdrawCount.name}：${withdrawCount.param}&nbsp;&nbsp;${withdrawCount.unit}</p>
	</div>
	<div class="weui-cell__ft"></div>
</div>

<div id="myModal" hidden style="background-color:#ffffff;opacity:1 !important;position:relative;z-index:2000;margin-top:-60%;height:180px;">

            <div class="header" style="border-bottom:1px solid #e5e5e5;height:50px;">
                <button type="button" id="close" style="line-height:50px;float:right;width:40px;height:40px;border:none;background-color:white;font-size:20px;color:#b1a5a5">x</button>
                <span style="line-height:50px;font-size:20px;padding-left:10px">请输入支付密码</span>
            </div>
            
  <div class="body" style="padding:15px 10px 0 10px;height:70px">          
    <div class="paycontainer">
        <input type="tel" autofocus="autofocus" id="password" minlength="6" maxlength="6" class="paypasswordcontainer "
               oncontextmenu="return false" onpaste="return false" oncopy="return false"  
               oncut="return false" autocomplete="off">
        <div class="sixpassword">
            <i class="active"><b></b></i>
            <i><b></b></i>
            <i><b></b></i>
            <i><b></b></i>
            <i><b></b></i>
            <i><b></b></i>
            <span class="guangbiao"></span>
        </div>
    </div>
</div>
      <div class="footer" style="height:50px;padding-top:5px">
           <a href="<c:url value='/wechat/cust/customerIden/retrievePassword'/>" style="font-size:20px;float:right;padding-right:20px;padding-bottom:0px;color:#00ace2">忘记密码</a>
           <!-- <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
           <button type="button" class="btn btn-primary" id="confirmPassword">确认</button> -->
      </div>

</div>
<div hidden id="cover"></div>

<%@ include file="/WEB-INF/views/shared/scripts/jquery.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/jqweui.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/weContentFooter.jsp"%>

<script type="text/javascript">

$(function() {
	
	/* 点击提现须知*/
	$("#share-father").on("click", function() {
		if ($(this).attr("class").indexOf("weui-cell_access") > 0) {
			$(this).removeClass("weui-cell_access");
			$(this).addClass("weui-cell_define");
		} else {
			$(this).removeClass("weui-cell_define");
			$(this).addClass("weui-cell_access");
		}

		$("#shareLevel").toggle(500);
	});
});

var minMoney = $(".minMoney").val();

	function btnColor() {
		var $withdraw = $(".withdraw");
		var $money = $("#money");
		var value = $money.val();
		if (value != '') {
			$("#btn").attr("disabled", false); 
			if ($withdraw.attr("class").indexOf("weui-btn_disabled") > 0) {
				$withdraw.removeClass("weui-btn_disabled");	
			}
		}
		if (value == ''|| value == 0 || value <parseFloat(minMoney)) {
			$("#btn").attr("disabled", true); 
			$withdraw.addClass("weui-btn_disabled");			
		}
	}
	
	//点击提现按钮要执行的操作 
	function withdraw() {
		if (!checkInput()) {
			return;
		}
		$("#cover").show();
		$("#myModal").show();
		$("#password").trigger("click").focus();
		$("#password").val("");
		$input = 0;
		checkPassword();
	} 
	
	//执行提现操作
	function confirm(){
		var money = $("#money").val();
		var action = $.getVirtualPath()+"/wechat/acc/myWealth/submitApplication";
		$.ajax({
			url:action,
			type:'post',
			dataType:'json',
			data:{money:money},
			success:function(res){
				
				if (res.result == 'true' ) {
					var allmoney = $(".allMoney").val();
					$(".moneyNum").html(parseFloat(allmoney)-parseFloat(money));
					if(res.message != 'pass'){//需要审核
						$.alert(res.message);   
						 setTimeout(function(){//两秒后跳转  
                             window.location.href=$.getVirtualPath()+"/wechat/acc/myWealth/resultDetail?changeMoney="+money;
                          },2000);  
													
					}else{
						var key = res.key;
						var url = $.getVirtualPath()+"/wechat/acc/myWealth/toConfirm";
						var result=$.getTextPost(url,"key="+key);

						window.location.href=$.getVirtualPath()+"/wechat/acc/myWealth/balanceDetail";

					} 
						
				} else {
					$.alert(res.message);
				}
			}
		});
	}
	
	/* 检查输入 */
	function checkInput() {
		if (checkMoney()) {
			return true;
		}
		return false;
	}
	/* 检查是否输入金额 */
	function checkMoney() {
		var money = $("#money").val();
		$(".money").val(money);
		
		var reg = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^(0){1}$)|(^\d\.\d{1,2}?$)/;
		if (money == '' || money == '0' || money == '0.0' ||  money == '0.00') {
			$("#btn").attr("disabled", false);
			$(".info").hide();
			return false;
		}
		else if(!reg.test(money)){
			$(".info").html("请输入正确的金额");
			$(".info").show();
			var $withdraw = $(".withdraw");
			$withdraw.addClass("weui-btn_disabled");
			
			/* $.toptip("请输入正确的金额","error"); */
			return false;
		}else if (money<parseFloat(minMoney)) {
			$("#btn").attr("disabled", false);
			$(".info").html("提现最小额度为"+minMoney+"元");
			$(".info").show();
			return false;
		}
		
		var allmoney = ${accountInfo.balance};
		if(money>allmoney){
			$(".info").html("提现金额超出可用金额");
			$(".info").show();
			var $withdraw = $(".withdraw");
			$withdraw.addClass("weui-btn_disabled");
			return false;
		}
		$(".info").hide();
		
		return true;
	}
	
	//全部提现的实现
	function withdrawals(){		
		var allmoney = ${accountInfo.balance};
		$("#money").val(allmoney);
		checkMoney();
		btnColor();
		
	}
	
	//检测密码是否正确
	function confirmPass() {
		var password=$("#password").val();
		//把密码传入controller得到返回结果
		var url = $.getVirtualPath()+"/wechat/acc/myWealth/toConfirmPassword";
		var result=$.getTextPost(url,"password="+password);
		/* alert(result); */
		if(result == "true"){
			//密码匹配正确 执行提现操作
			confirm();
		}else if(result == "false"){
			$.toast("<p>密码错误</p><p>请重新输入</p>","text");
		}
	};
	//点击x 隐藏输入框和遮罩层
	$("#close").on("click",function(){
		$("#cover").hide();
		$("#myModal").hide();	

	})
	/* --------------6位密码支付的js-------------------- */
	 $(function(){
	        $(".paypasswordcontainer").keyup(function(){
	           $input_val=$(this).val(); 
	            $input=$input_val.length;
	            if($input==6){
	               //检测密码是否正确
	            	confirmPass();

	           	   $("#cover").hide(); 
	    		   $("#myModal").hide(); 
	               //初始化密码的值与长度
	    		   $input=0;
	               $(this).val("");
	            }
	            checkPassword();
	        })

	    });
	
	//根据输入密码显示密码的样式
	    function checkPassword(){
		if ($input == 0) {
            $(".sixpassword").find("i").eq(0).addClass("active").siblings("i").removeClass("active");
            $(".sixpassword").find("b").css({"display": "none"});
            $(".guangbiao").css({"left": 0});
        }
        else if ($input == 6) {
            $(".sixpassword").find("b").css({"display": "block"});
            $(".sixpassword").find("i").eq(5).addClass("active").siblings("i").removeClass("active");
            $(".guangbiao").css({"left": 5 * 50});
        }else{
            $(".sixpassword").find("i").eq($input).addClass("active").siblings("i").removeClass("active");
            $(".sixpassword").find("i").eq($input).prevAll("i").find("b").css({"display":"block"});
            $(".sixpassword").find("i").eq($input).nextAll("i").find("b").css({"display":"none"});
            $(".guangbiao").css("left",$input*50);
        }
	}
</script>